<?php
namespace app\api\service;
use think\Controller;
use think\Db;

class Brand extends Controller {
    static protected $err_code = 0;
    //获取品牌列表
    static public function brand_list() {
        try {
            $brand = db('brand')->order('mark asc')->select();

            $brand_group = db('brand')->field('mark')->group('mark')->order('mark asc')->select();
            return ['code' => 200, 'data' => ['brand' => $brand, 'brand_group' => $brand_group], 'msg' => 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code' => self::$err_code, 'msg' => 'FAULT'];
        }
    }

    // 获取品牌详情
    static public function get_brand_info($param) {
        if(!isset($param['brand_id'])) return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        try {
            $brand= db('brand')->where('id', $param['brand_id'])->find();
            return ['code' => 200, 'data' => $brand, 'msg' => 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code' => self::$err_code, 'msg' => 'FAULT'];
        }
    }

    //获取品牌型号
    static public function brand_model_list($param) {
        if(!isset($param['brand_id'])) return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        try {
            $models= db('model')->where('brand_id', $param['brand_id'])->select();
            return ['code' => 200, 'data' => $models, 'msg' => 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code' => self::$err_code, 'msg' => 'FAULT'];
        }
    }

    // 获取品牌型号详情
    static public function get_brand_model_info($param) {
        if(!isset($param['model_id'])) return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        try {
            $model = db('model')->where('id', $param['model_id'])->find();
            return ['code' => 200, 'data' => $model, 'msg' => 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code' => self::$err_code, 'msg' => 'FAULT'];
        }
    }
}





